﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Catering_Rules;
using System.Data;

namespace Catering.Catering_Page.ShanShiFenXi
{
    public partial class Edit_IntroduceNutrition : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loadData();

            }
        }
        private void loadData()
        {
            Catering_Rules.NutritionType nTRule = new Catering_Rules.NutritionType();
            DataTable dtNT = nTRule.GetAll();
            for (int i = 0; i < dtNT.Rows.Count; i++)
            {
                TreeNode temp = new TreeNode() { Text = dtNT.Rows[i]["nutrition"].ToString(), Value = dtNT.Rows[i]["id"].ToString() };
                TreeView1.Nodes.Add(temp);

                ListItem lI = new ListItem() { Text = dtNT.Rows[i]["nutrition"].ToString(), Value = dtNT.Rows[i]["id"].ToString() };
                DropDownList1.Items.Add(lI);
            }

        }
        protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
        {
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtContent.Text) || string.IsNullOrEmpty(txtTitle.Text) || DropDownList1.SelectedItem == null)
            {
                return;
            }
            Catering_Model.IntroduceNutritionDBInfo info = new Catering_Model.IntroduceNutritionDBInfo();
            info.Title = txtTitle.Text;
            info.CText = txtContent.Text;
            info.Typeid = Int32.Parse(DropDownList1.SelectedItem.Value);
            info.UserId = 0;
            Catering_Rules.IntroduceNutrition INRules = new Catering_Rules.IntroduceNutrition();
            if (INRules.AddIN(info))
            {
                Response.Write(@"<script>alert('提交成功！')</script>");
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (string.IsNullOrEmpty(txtSearch.Text))
            {
                return;
            }
            for (int i = 0; i < TreeView1.Nodes.Count; i++)
            {
                for (int ii = 0; ii < TreeView1.Nodes[i].ChildNodes.Count; ii++)
                {
                    if (TreeView1.Nodes[i].ChildNodes[ii].Text.Contains(txtSearch.Text))
                    {
                        TreeView1.Nodes[i].ChildNodes[ii].Selected = true;
                        break;
                    }
                }
            }
        }
    }
}